;(function () {
  new Vue({
    el: '#financialConfig',
    data: {
      wrokList: [],
      offOn: [{name: '开启', code: '1'}, {name: '关闭', code: '0'}],
      workFlag: false,
      quanxian: JSON.parse(localStorage.getItem('permissions')),
      quanxian2: JSON.parse(localStorage.getItem('userMes')),
      isEntry:false,
      unitsList:[],
      rentList:[],
      rent_count:'',
      selectedData:[],
      isMustInvoice:false,
      mustInvoiceObj:{}
    },
    methods: {
      invoicingOpen(){
        hlUrlUtil.goTo('invoicingLimit', {ddtab:true})
      },
      goToAutoSubmit: function () {
        hlUrlUtil.goTo('billConfig', {ddtab:true})
      },
      goToIncomeSure: function () {
        hlUrlUtil.goTo('incomeSure', {ddtab:true})
      },
      goToDistribution: function () {
        hlUrlUtil.goTo('distribution', {ddtab:true})
      },
      goToFinancialDocument:function(){
        hlUrlUtil.goTo('finicialDocumentHome', {ddtab:true})
        sessionStorage.removeItem("accountId"); 
      },
      entryBut(){
        this.isEntry = !this.isEntry
      },
      getWorkConfig: function () {
        var self = this;
        hlhttp.get({
          url: 'configure/bpm_config/dict',
          success: function (res) {
            res.map(function (item, index) {
              item.flag = true;
              if (index == 1) {
                if (res[0].value == 0) {
                  item.flag = false
                }
              }
            })
            self.wrokList = res
          }
        })
      },
      postWorkconfig: function (i, s) {
        var data = [];
        this.wrokList[i].value = s;
        var self = this;
        if (i == 0) {
          if (s == 0) {
            this.wrokList[1].value = s;
          }
        }
        this.wrokList.map(function (item, index) {
          data.push({code: item.code, value: item.value})
        })

        hlhttp.put({
          url: 'configure/bpm_config/dict',
          data: {
            config_info: JSON.stringify(data)
          },
          success: function () {
            hl.toast('操作成功')
            self.getWorkConfig()
          }
        })
      },
      // 选中的租金计算周期字典
      getSelectItem(val){
        hlhttp.put({
          url: 'configure/annual_day_config',
          data: {
            "dict_name": val[0].dictName,
            "dict_value": val[0].dictValue,
            "dict_property":  val[0].dictProperty,
          },
          success: function () {
            hl.toast('设置成功')
          }
        })
      },
      // 获取选中租金计算周期
      getSelfRent(){
        var that = this
        hlhttp.get({
          url: 'configure/dict',
          data: {
            module_code: 'CIWU',
            config_name: 'CW_RENT_CALCULATE_PERIOD_TYPE_CONFIG',
          },
          success: function (res) {
            that.selectedData = [res[0].dictValue]
          }
        })
      },
      //获取租金计算周期字典
      getRent() {
        var that = this
        hlhttp.get({
          url: 'configure/dict',
          data: {
            module_code: 'CIWU',
            config_name: 'CW_RENT_CALCULATE_PERIOD_TYPE',
          },
          success: function (res) {
            res.map(item =>{
              item.name = item.dictName
              item.code = item.dictCode
            })
            that.rentList = res
          }
        })
      },
      //选择租金计算方式
      selectedRent(item){
        this.rent_count = item.dictCode
        this.rent_name = item.dictName
      },
      getInitInvoice(){
        hlhttp.get({
          url: 'configure/dict',
          data: {
            module_code: 'CIWU',
            config_name: 'CW_INVOCATION_REQURIED_CONFIG',
          },
          success: (res) => {
            this.isMustInvoice = res[0].dictValue=='N'?false:true
            this.mustInvoiceObj = res[0]
          }
        })
      },
      changeMustInvoice(){
        hlhttp.put({
          url: 'configure/tenant_dict_config',
          data: {
            module_code:'CIWU',
            config_name:'CW_INVOCATION_REQURIED_CONFIG',
            status: this.isMustInvoice?"Y":'N',
            dict_code: this.mustInvoiceObj.dictCode,
            dict_value:this.isMustInvoice?"Y":'N',
            dict_display_name:'#',
            dict_property:'#',
            default_flag:this.mustInvoiceObj.defaultFlag,
            config_type:this.mustInvoiceObj.configType,
            dict_name:this.mustInvoiceObj.dictName
          },
          success: ()=> {
            this.getInitInvoice()
          }
        })
      }
    },
    mounted: function () {
      hlSelectUi()
      this.getWorkConfig()
      this.getRent()
      this.getSelfRent()
      this.getInitInvoice()
    }
  })
} ())
